package com.ellricky.excute_president.ui.fragment

import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.andr.common.ui.fragment.BaseToolBarFragment
import com.andr.common.ui.mvp.BasePresenter
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.adapter.course.JobTrainingActivity
import com.ellricky.baselib.cache.LocalCacheUtil
import com.ellricky.baselib.ui.ActiveDocActivity
import com.ellricky.baselib.ui.ErCodeActivity
import com.ellricky.baselib.ui.cla.ClassManageFragment
import com.ellricky.baselib.ui.clue.ClueLibActivity
import com.ellricky.baselib.ui.order.RenewalManageActivity
import com.ellricky.baselib.ui.student.StudentManageActivity
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.excute_president.R

import kotlinx.android.synthetic.main.pd_fragment_home.*

class PresidentMainFragment :
    BaseToolBarFragment<Void, BasePresenter<Void>>()/*, RvRefreshListener, AdapterView.OnItemClickListener */ {

    private lateinit var classManageFragment: ClassManageFragment

    companion object {
        fun newInstance(): PresidentMainFragment {
            val fragment = PresidentMainFragment()
            val bundle = Bundle()
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun getContentLayout(): Int = R.layout.pd_fragment_home

    override fun initUIView(root: View) {
        super.initUIView(root)
        mTvTitle.setText(R.string.pd_home)
        setRightBtn(R.drawable.base_icon_ercode)

        tvStuManage.setOnClickListener(this)
        tvFileLearn.setOnClickListener(this)
        tvMakeUpList.setOnClickListener(this)
        tvClassManage.setOnClickListener(this)

        tvJobTraining.setOnClickListener(this)
        tvActiveDoc.setOnClickListener(this)
        tvRecentlyCourse.setOnClickListener(this)
        tvClueLib.setOnClickListener(this)

        classManageFragment = ClassManageFragment.newInstance(true)
        childFragmentManager.beginTransaction()
            .replace(R.id.frgContainer, classManageFragment)
            .commit()
        initLeftIcon()
    }

    private fun initLeftIcon() {
        val btnLeft = view?.findViewById<TextView>(R.id.btn_left)
        btnLeft?.visibility = View.VISIBLE
        btnLeft?.background =
            ContextCompat.getDrawable(requireContext(), R.drawable.base_bg_btn_black_bg)
        btnLeft?.setTextColor(ContextCompat.getColor(requireContext(), R.color.white))
        btnLeft?.text = "投诉记录"

        btnLeft?.setOnClickListener {
            EAppUtil.jumpCommonFragment(
                requireContext(),
                BaseConstant.FRAGMENT_COMPLAIN_RECORD,
                null
            )

        }
    }

    override fun onResume() {
        super.onResume()
        val load = LocalCacheUtil.isReloadData()
        if (load) classManageFragment.loadClassRooms()
        LocalCacheUtil.setIsReloadData(true)
    }

    override fun onClickView(view: View) {
        super.onClickView(view)
        when (view) {
            tvStuManage -> {
                EAppUtil.jumpPageWithNoParam(mContext, StudentManageActivity::class.java)
            }
            tvFileLearn -> {
                EAppUtil.jumpCommonFragment(context, BaseConstant.FRAGMENT_ORDER_MANAGER, null)
            }
            tvMakeUpList -> {
                EAppUtil.jumpCommonFragment(context, BaseConstant.FRAGMENT_CLASS_CONSUME, null)
            }
            tvClassManage -> {
                EAppUtil.jumpClassManage(this)
            }
            tvJobTraining -> {
                EAppUtil.jumpPageWithNoParam(mContext, JobTrainingActivity::class.java)
            }
            tvActiveDoc -> {
                EAppUtil.jumpPageWithNoParam(mContext, ActiveDocActivity::class.java)
            }
            tvRecentlyCourse -> {
                EAppUtil.jumpPageWithNoParam(
                    mContext,
                    RenewalManageActivity::class.java
                )
            }
            tvClueLib -> {
                EAppUtil.jumpPageWithNoParam(mContext, ClueLibActivity::class.java)
            }
        }
    }


    override fun onClickBtnRight() {
        super.onClickBtnRight()
        EAppUtil.jumpPageWithNoParam(this, ErCodeActivity::class.java)
    }

}
